package com.smartservice.ui;

import org.zeroxlab.widget.AnimationLayout;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ListView;

import com.aphidmobile.flip.FlipViewController;
import com.aphidmobile.flip.demo.adapter.TravelAdapter;

@SuppressLint({ "NewApi", "HandlerLeak", "ShowToast" })
public class Home extends FragmentActivity implements AnimationLayout.Listener {
	//private TabHost mTabHost;
	TabFragmentSeason frg;
	String idTabAttach = null;
	ListView lv_menu;
	//ArrayList<Episode> episodes = new ArrayList<Episode>();
	//ArrayList<Series> series = new ArrayList<Series>();
	public AnimationLayout mLayout;
	public FlipViewController flipView;
	// apply JSON to list view


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	    flipView = new FlipViewController(this);

	    //Use RGB_565 can reduce peak memory usage on large screen device, but it's up to you to choose the best bitmap format 
	  //  flipView.setAnimationBitmapFormat(Bitmap.Config.RGB_565);

	    flipView.setAdapter(new TravelAdapter(this));

	    setContentView(flipView);
	 //   flipView.setFlipByTouchEnabled(false);
		//setContentView(R.layout.activity_home);
		//FlipViewController flipView;
//	    flipView = new FlipViewController(this);
//
//	    //Use RGB_565 can reduce peak memory usage on large screen device, but it's up to you to choose the best bitmap format 
//	  //  flipView.setAnimationBitmapFormat(Bitmap.Config.RGB_565);
//
//	    flipView.setAdapter(new TravelAdapter(this));
//
//	    setContentView(flipView);
		
//		mLayout = (AnimationLayout) findViewById(R.id.animation_layout);
//		mLayout.setListener(this);
//
//		// Creating menu list
//		lv_menu = (ListView) findViewById(R.id.lv_menu);
//		lvAdapterMenu mAdapter = new lvAdapterMenu(Home.this);
//
//		// add item for main menu
//		mAdapter.addItem("Đăng nhập");
//		//mAdapter.addImageItem(R.drawable.img_btn_menu);
//		mAdapter.addSeparatorItem("Danh mục");
//		mAdapter.addItem("Deal Được thích");
//	//	mAdapter.addImageItem(R.drawable.img_btn_back);
//		mAdapter.addItem("Quản lý đơn hàng");
//		mAdapter.addItem("Sửa địa chỉ nhập hàng");
//		mAdapter.addItem("Lịch sử ví mua chung");
//		mAdapter.addItem("Điểm thưởng");
//		mAdapter.addItem("Nạp tiền");
//		mAdapter.addSeparatorItem("Hệ thống");
//		mAdapter.addItem("Sắp xếp Deal");
//		mAdapter.addItem("Thoát");
//		lv_menu.setAdapter(mAdapter);
//		lv_menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
//					long arg3) {
//				// TODO Auto-generated method stub
//
//				 if(arg2==0){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==2){
//					 Intent intentDealDuocThich=new Intent(Home.this,DealDuocThich2.class);
//					 startActivity(intentDealDuocThich);
//				 }
//				 if(arg2==3){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==4){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==5){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==6){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==7){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==8){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==9){
//					 Intent intentDangNhap=new Intent(Home.this,Dangnhap.class);
//					 startActivity(intentDangNhap);
//				 }
//				 if(arg2==10){
//					 finish();
//				 }
//					 
//			}
//		});
//		 
//		// Toogle menu button
//		ImageButton btn_toogle_menu = (ImageButton) findViewById(R.id.btn_toogle);
//		btn_toogle_menu.setOnClickListener(new View.OnClickListener() {
//
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				mLayout.toggleSidebar();
//			}
//		});
		

		// check network connection;
	//	ConnectionDetector check = new ConnectionDetector(Home.this);
//		if (!check.isConnectingToInternet()) {
//			Toast ts = Toast.makeText(Home.this, constant.NETWORK_ERROR,
//					constant.TOAST_DURATION);
//			ts.show();
//			return;
//		}

		// feed JON of serial
//		new JSONParserTask(constant.URL_GET_LIST_CONTENT_OF_APP_ID,
//				constant.BD_JSON_KEY_SERIAL, mHandler).execute();
	}


//	private void addFragmentContent(String id, Boolean pressTab) {
//		// add content of first tab
//		FragmentTransaction frt = this.getSupportFragmentManager()
//				.beginTransaction();
//		if (pressTab) {
//			frt.remove(frg);
//		}
//		Bundle bd = new Bundle();
//		bd.putString(constant.BD_ID_FRAGMENT, id);
//		frg = new TabFragmentSeason();
//		frg.setArguments(bd);
//		frt.add(R.id.realtabcontent, frg, id);
//		frt.commit();
//		idTabAttach = id;
//	}

	public void onBackPressed() {
		// TODO Auto-generated method stub
		if (mLayout.isOpening()) {
			mLayout.closeSidebar();
		} else {
			finish();
		}
	}

	public void onSidebarOpened() {
		// TODO Auto-generated method stub
		flipView.setFlipByTouchEnabled(false);

	}

	public void onSidebarClosed() {
		// TODO Auto-generated method stub
		flipView.setFlipByTouchEnabled(false);

	}

	public boolean onContentTouchedWhenOpening() {
		// TODO Auto-generated method stub
		mLayout.closeSidebar();
		return false;
	}

	
}
